package com.zz.service;

import java.util.List;
import java.util.Optional;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.zz.entity.Supplier;

import com.zz.repository.SupplierRepository;

@Service
public class SupplierService {
	@Resource
	SupplierRepository supplierRepository;
	public Page<Supplier> findAll(String page,String limit){
		Pageable pageable=PageRequest.of(Integer.parseInt(page), Integer.parseInt(limit));
		Page<Supplier>  pageinfo=supplierRepository.findAll(pageable);
		return pageinfo;	
	}
	public Optional<Supplier>findById(String id) {
		return supplierRepository.findById(id);
	}
	public List<Supplier> findByName(String name){
		return supplierRepository.findByNameLike("%"+name+"%");
	}
	public Supplier updatesupplier (Supplier supplier) {
		return supplierRepository.save(supplier);
	}
	public void deleteById(String id) {
		supplierRepository.deleteById(id);
	}
	public Supplier savesupplier(Supplier s) {
		return supplierRepository.save(s);
		
	}
}
